package com.ruoyi.web.controller.modules;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.category.Category;
import com.ruoyi.web.domain.category.Type;
import com.ruoyi.web.service.category.ICategoryService;
import com.ruoyi.web.service.category.ITypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 一级分类tt_typeController
 * 
 * @author zq
 * &#064;date  2024-01-09
 */
@Api(tags = "分类管理")
@RestController
@RequestMapping("/type")
public class TypeController extends BaseController
{

    private final ITypeService typeService;
    private final ICategoryService categoryService;

    public TypeController(ITypeService typeService, ICategoryService categoryService) {
        this.typeService = typeService;
        this.categoryService = categoryService;
    }
    /**
     * 查询一级分类tt_type列表
     */
    @ApiOperation("查询一级分类tt_type列表")
    @GetMapping("/list")
    public TableDataInfo<Type> list(Type type)
    {
        List<Type> list = typeService.selectTypeList(type);
        return getDataTable(list);
    }


    /**
     * 获取一级分类tt_type详细信息
     */
    @ApiOperation("获取一级分类tt_type详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(typeService.selectTypeById(id));
    }

    /**
     * 新增一级分类tt_type
     */
    @ApiOperation("新增一级分类")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Type type)
    {
        return toAjax(typeService.insertType(type));
    }


    /**
     * 修改一级分类tt_type
     */
    @ApiOperation("修改一级分类tt_type")
    @PutMapping
    public AjaxResult edit(@RequestBody Type type)
    {
        return toAjax(typeService.updateType(type));
    }

    /**
     * 删除一级分类tt_type
     */
    @ApiOperation("删除一级分类tt_type")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(typeService.deleteTypeByIds(ids));
    }

    /**
     * 获取二级分类管理详细信息 tt_category
     */
    @ApiOperation("获取二级分类管理详细信息")
    @GetMapping(value = "/level/{id}")
    public AjaxResult getLevelInfo(@PathVariable("id") String id)
    {
        return success(categoryService.selectCategoryById(id));
    }

    /**
     * 新增二级分类管理 tt_category
     */
    @ApiOperation("新增二级分类管理")
    @PostMapping("/level/insert")
    public AjaxResult add(@RequestBody Category category)
    {
        return toAjax(categoryService.insertCategory(category));
    }

    /**
     * 修改二级分类管理 tt_category
     */
    @ApiOperation("修改二级分类管理")
    @PutMapping("/level/edit")
    public AjaxResult edit(@RequestBody Category category)
    {
        return toAjax(categoryService.updateCategory(category));
    }

    /**
     * 删除二级分类管理 tt_category
     */
    @ApiOperation("删除二级分类管理")
    @DeleteMapping("/level/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(categoryService.deleteCategoryById(id));
    }
}
